<?php
ob_start();
ini_set('session.bug_compat_42',0);
ini_set('session.bug_compat_warn',0);
session_start();
error_reporting(6135);
require_once("configuration.php");
require_once("includes/db/constant.php");
require_once("includes/db/dbsetup.php");
define("TEMPLATE_NAME", 'blue/');

require_once("includes/MySmarty.class.php");
require_once('localization.php');
require_once('localization_func.php');
require_once("includes/util.php");


require_once("controller/Fconfig.class.php");
require_once("controller/FDocument.class.php");

require_once("model/FCountryBean.class.php");
require_once("controller/Paging.class.php");

require_once("model/FIN_categoryBean.class.php");
include_once("controller/Fcategory.class.php");
$smarty->assign("FOLDER_TEMPLATES", FOLDER_TEMPLATES);
$smarty->assign("TEMPLATE_NAME_PATH", TEMPLATE_NAME);
?>

<?php
	$WPath = FOLDER_HOST;	
	$document = new FDocument($db, $smarty);
	$page = '';
	$cat = '';
	$product = '';
	if ($WPath == '/') {
			$url = substr($_SERVER['REQUEST_URI'],1);
	} else {
			$url = preg_replace($WPath,"", $_SERVER['REQUEST_URI'],1);
			$url=explode("?",$url);
			//var_dump($url);
			$url = str_replace('//',"", $url[0]);
	}
	$url_array=explode("/",$url);
	if(isset($url_array[0]))
		$page = $url_array[0];
	if(isset($url_array[1])	)
		$cat = $document->khongdau($url_array[1]);
	if(isset($url_array[2]))
		$product = $document->khongdau($url_array[2]);
	$smarty->assign('WPATH',$WPath);

	$_REQUEST['page']=$page;
	$listcat = new Fcategory($db, $smarty,$WPath);
	$listcat->view_top_category();
	$listcat->view_bottom_category();
	$listcat->view_top_link();
	$listcat->view_categoryfooter();
	$config = new Fconfig($db, $smarty);
	$config->process();
	
	
	$page_op = $document->RewriteLinkToFile($page);
	$document->WritePath($WPath,$page,$cat,$product);
	$id = $document->GetIdFromLink($page);
	
	$option = "";
	if($option==""){
		$option = $page_op;
	}
	if (file_exists("controller/".$option.".class.php")){
		include_once("controller/".$option.".class.php");
		// we render html depend on parameter
		if($option != ""){
			//we use @ sign to ignore error and do not show any thing
			@($$option = new $option($db, $smarty,$page,$cat,$product));
			$$option->main();
		}
	}
	//Show page
	
	
ob_end_flush();	
?>